/*
It can be seen that the number, 125874, and its double, 251748, contain 
exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 
6x, contain the same digits.
*/

Integer.metaClass.sortedDigits = {
    delegate.toString().toList().sort().join().toInteger()
}

Integer.metaClass.sameDigits = { x ->
    if (x == delegate) return true
    return x.sortedDigits() == delegate.sortedDigits()

}

boolean rot6(n) {
    for (i in 2..6) {
        if (!n.sameDigits(n * i)) return false
    }
    return true
}

n = 123456
while (!rot6(n)) n++
for (i in 1..6) println "$n * $i = ${n * i}"
